package com.beidouapp.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import com.beidouapp.dao.RoleDao;
import com.beidouapp.domain.example.RoleExample;
import com.beidouapp.domain.pojo.Role;
import com.beidouapp.mapper.BaseMapper;
import com.beidouapp.mapper.RoleMapper;

@Repository
public class RoleDaoImpl extends BaseDaoImpl<Role> implements RoleDao {

	@Autowired
	private RoleMapper roleMapper;

	@Override
	public BaseMapper<Role> getResourceMapper() {
		return this.roleMapper;
	}

	@Override
	public List<Role> findRolesByEmpId(Long empId) {
		return roleMapper.findRolesByEmpId(empId);
	}

	@Override
	public List<Role> findRolesByOrgId(Long orgId) {
		return roleMapper.findRolesByOrgId(orgId);
	}

	@Override
	public int insert(Role record) {
		// record.setId(UUIDGenerator.get32UUID());
		// record.setIsDel("N");
		// record.setCreateTime(new Date());
		return roleMapper.addEntry(record);
	}

	@Override
	public int update(Role record) {
		return roleMapper.modifyEntry(record);
	}

	@Override
	public List<Role> findRolesByMap(Map<String, Object> params) {
		return roleMapper.findRolesByMap(params);
	}

	// ----------------------

	@Override
	public List<Role> findRoleById(Long userId) {
		return roleMapper.findRoleById(userId);
	}

	@Override
	public int countByExample(RoleExample example) {
		return roleMapper.countByExample(example);
	}

	@Override
	public int deleteByExample(RoleExample example) {
		return roleMapper.deleteByExample(example);
	}

	@Override
	public int insertSelective(Role record) {
		// record.setId(UUIDGenerator.get32UUID());
		// record.setCreateTime(new Date());
		return roleMapper.insertSelective(record);
	}

	@Override
	public List<Role> selectByExample(RoleExample example) {
		return roleMapper.selectByExample(example);
	}

	@Override
	public int updateByExampleSelective(Role record, RoleExample example) {
		return roleMapper.updateByExampleSelective(record, example);
	}

	@Override
	public int updateByExample(Role record, RoleExample example) {
		return roleMapper.updateByExample(record, example);
	}

	@Override
	public int updateByPrimaryKeySelective(Role record) {
		return roleMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(Role record) {
		return roleMapper.updateByPrimaryKey(record);
	}

	@Override
	public List<Role> findPageRoles(Map<String, Object> params, Integer offset, Integer limit) {
		return roleMapper.findPageRoles(new RowBounds(offset, limit), params);
	}

	@Override
	public long countPageRoles(Map<String, Object> params) {
		return roleMapper.countPageRoles(params);
	}

	@Override
	public Role findRolesByRoleCode(String orgCode) {
		Role r = new Role();
		r.setCode(orgCode);
		List<Role> list = this.findEntryList(r);
		if (!CollectionUtils.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public Role findRoleByFkId(String fkId) {
		return roleMapper.findRoleByFkId(fkId);
	}

	@Override
	public int removeEntryByFKID(String fkId) {
		return roleMapper.removeEntryByFKID(fkId);
	}

	@Override
	public List<Role> findRolesByDepartmentId(String departmentId) {
		return roleMapper.findRolesByDepartmentId(departmentId);
	}

}
